import pg
import pprint

# class DataOutSchema()

def get_ariadna() -> list:
    result = pg.select(f"""SELECT TO_CHAR(r.dat, 'DD.MM.YYYY HH24:MI:SS') AS dd
      ,TO_CHAR(r.updatedate, 'DD.MM.YYYY HH24:MI:SS') AS updatedate
      ,d.text AS dep_text
      ,sp.text AS spec_text
      ,dd.text AS doc
      ,p.num
      ,INITCAP(p.lastname) AS lastname
      ,INITCAP(p.firstname) AS firstname
      ,INITCAP(p.secondname) AS secondname
      ,TO_CHAR(p.birthdate, 'DD.MM.YYYY') AS birthdate
      ,p.phone
      ,p.cellular
      ,r.note
      ,r.keyid
    FROM rnumb r
      ,docdep dd
      ,dep d
      ,lu sp
      ,patient p
      ,lu l
      ,visit v
    WHERE r.stacid = l.keyid
     AND v.keyid = r.visitid 
     AND l.tag = 29
  -- AND l.code = 15
     AND r.patientid IS NOT NULL
     AND p.keyid = r.patientid
     AND r.docdepid = dd.keyid
     AND d.keyid = dd.depid
     AND sp.keyid = dd.specid
     AND v.createby = -2
     AND TRUNC(r.dat)>= NOW()
     -- BETWEEN :DAT1 AND :DAT2
     AND (CAST('001' AS VARCHAR) IS NULL OR substr(fn_get_dep_sortcode(d.keyid), 1, 3)= '001')
    ORDER BY r.dat, d.text, sp.text, dd.text """)
    # pprint.pprint(result)
    return result